<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../vue.global.js'></script>
</head>

<body>
    <div id='app'>
        <!-- isActive成立时 div有active类名 -->
        <!-- <div class="abc">1</div> -->
        <div :class="{ active: isActive }">1</div>

        <!-- nimei是一个静态class active与text-danger两个class是否存在取决于变量的值 -->
        <div class="nimei" :class="{ active: isActive, 'text-danger': hasError }">2</div>
        
        <!-- 写变量的名字与写变量的值 没有任何卵区别 -->
        <div :class="classObj">3</div>

        <!-- 使用计算属性求取div的class 当依赖项没有发生变化时  组件重新渲染计算属性也不会被重新计算 而是使用上一次的缓存 -->
        <div :class="classObjectComputed">4</div>
    </div>
    
    <script>
        const app = Vue.createApp({
            data() {
                return {
                    isActive: true,
                    hasError: 123,
                    error: {
                        type: 'fatal'
                    },
                    classObj: {active:true,'text-danger':false}
                }
            },
            computed: {
                classObjectComputed() {
                    console.log("classObjectComputed");
                    return {
                        active: this.isActive && !this.error,
                        'text-danger': this.error && this.error.type === 'fatal'
                    }
                }
            }
        })
        const vm = app.mount('#app')
    </script>
</body>

</html>